* Wrapper command to make ritest run more than one regression
cap program drop two_estimates
program two_estimates, eclass
	syntax, command1(string) command2(string) estimate1(string) estimate2(string)
	* Extract coefficient and SE from first regression
	`command1'
	local b1  = `estimate1'
	local se1 = `estimate2'
	
	* Extract coefficient and SE from second regression
	`command2'
	estadd scalar b1  = `b1'
	estadd scalar se1 = `se1'
	estadd scalar b2  = `estimate1'
	estadd scalar se2 = `estimate2'
end


cap log close

global path = "****"

local name= "randomized_inf"  
local date = "110419"
global logname = "$path/`name'_`date'.log"

clear
set more off
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample.dta", clear


*age restriction
keep if age_2017<65 & age_2017>=45

*prior year restriction
drop if covered2016-any_dec==11

cap erase "$path/placebo_dist_`date'.dta"
			  
* Run the permutations
ritest treatment e(b1) e(se1) e(b2) e(se2),  ///
			seed(387) reps(1000) 						///
			cluster(tin) strata(cluster1) 			///
			saving("$path/placebo_dist_`date'.dta"): ///
			two_estimates, command1 (reg dead17 treatment, cluster(tin)) ///
					       command2 (reg dead1718 treatment, cluster(tin)) ///
					       estimate1(_b[treatment]) estimate2(_se[treatment]) 

			 
			
log close
